# coding=utf-8
#

"""
发送邮件模块
"""

from django.conf import settings

from email.mime.text import MIMEText
from email.header import Header
from smtplib import SMTP_SSL

from config import HOST_SERVER
from config import SENDER_QQ
from config import SENDER_QQ_MAIL
from config import MAIL_PASSWORD
from config import RECEIVER
from utils.redis import get_eth_monitor_key
from utils.redis import add_eth_monitor_key


def send_mail(symbol: str, price: float, side: float, op_price: float):
    """
        发送邮件模块

        Args:
            :params: symbol(str): 币对
            :params: price(float): 操作点位
            :params: side(float): 操作方向1.0 -> 做多; -1.0 -> 做空;
            :params: op_price(float): 操作点位

        Returns:
            None
    """

    # 开始发送邮件
    # 邮件正文
    side_str = "做多" if side == 1.0 else "做空"
    mail_content = "操作提醒,操作币: %s, 操作为: %s, 当前点位:%s, 操作点位: %s" % (symbol, side_str, price, op_price)

    #邮件标题
    mail_title = '操作提醒'

    #ssl登录
    smtp = SMTP_SSL(settings.HOST_SERVER)
    #smtp.set_debuglevel(1)
    smtp.ehlo(settings.HOST_SERVER)
    smtp.login(settings.SENDER_QQ, settings.MAIL_PASSWORD)

    msg = MIMEText(mail_content, "plain", 'utf-8')
    msg["Subject"] = Header(mail_title, 'utf-8')
    msg["From"] = settings.SENDER_QQ_MAIL
    msg["To"] = ",".join(settings.RECEIVER)
    smtp.sendmail(settings.SENDER_QQ_MAIL, settings.RECEIVER, msg.as_string())
    smtp.quit()
